import axios from 'axios'


import { fetchBimfaceBasicInfo,  } from '@/api/auth/bimface';
// 创建axios实例
const service = axios.create({
  baseURL: "/bimface", // api 的 base_url
  timeout: 50000, // 请求超时时间
})

// request拦截器
service.interceptors.request.use(
  async(config) => {
    const token = (await fetchBimfaceBasicInfo()) as any;
    if (token && (config as any )?.requestOptions?.withToken !== false) {
      config.headers.Authorization =  `Bearer ${token}`
   
    }
    return config;
  },
  error => {
    console.log(error) // for debug
    Promise.reject(error)
  }
)

// response 拦截器
service.interceptors.response.use(
  response => {
    const res = response.data
  
    return res
  },
  error => {
    console.log('err' + error) // for debug
  
    return Promise.reject(error)
  }
)
export default service
